/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.tool;

import java.awt.*;

import com.funcom.peeler.ResourceLoader;
import com.funcom.peeler.UpdateCont;
import com.funcom.peeler.WorkBench;
import com.funcom.peeler.action.Change;
import com.funcom.peeler.adapter.KeyAndMouseAdapter;
import com.funcom.peeler.peelable.PeelComponent;
import com.funcom.peeler.symbol.Symbol;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Mouse;
import com.jmex.bui.BCursor;
import com.jmex.bui.BImage;
import com.jmex.bui.BRootNode;
import com.jmex.bui.BWindow;

import javax.imageio.ImageIO;
import java.awt.event.*;
import java.awt.image.BufferedImage;

/**
 * Abstract class acting as the basis for Tool that the WorkBench
 * sends it's input events to. Keeps easy access objects to the workbench,
 * the workbench's bui and the BRootNode that the bui has.
 */
public abstract class Tool extends KeyAndMouseAdapter{

    protected BCursor toolCursor;
    protected WorkBench workbench;
    protected WorkBench.Bui bui;
    protected BRootNode bui_root;

    protected Change change;

    /**
     * Constructs a Tool, makes sure workbench is not null
     * @param workbench the WorkBench this tool acts on
     */
    public Tool( WorkBench workbench ) {
        if ( workbench == null ) throw new RuntimeException( "Workbench must be defined when constructing a Tool" );
        this.workbench = workbench;
        this.bui = workbench.getBui();
        this.bui_root = bui.getSceneRoot();


    }

    /**
     * Run when the Tool is selected, initialization code goes here
     */
    public void select() {

        if (this instanceof ResizeTool) {            
            bui.getCanvas().setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));
        }
        if (this instanceof PanTool) {
            bui.getCanvas().setCursor(new Cursor(Cursor.HAND_CURSOR));        
        }
        if (this instanceof SelectionBoxTool) {
            bui.getCanvas().setCursor(new Cursor(Cursor.MOVE_CURSOR));
        }
    }

    /**
     * Run when the Tool is deselected, deinitialization code goes here
     */
    public void deSelect( ) {
        bui.getCanvas().setCursor(Cursor.getDefaultCursor());
    }
}
